﻿using System;

using Fuse8.DomainFramework.Common;
using Fuse8.ContentManagementFramework.Domain.Bases;

namespace Fuse8.ContentManagementFramework.Domain
{
    /// <summary>
    /// Entity which can be existing in concrete site, concrete site group (all sites in site group) or all site group
    /// </summary>
    /// <remarks>
    /// This used conception of sites in sitegroups
    /// </remarks>
    public interface ISiteAwareEntityObject
    {
        /// <summary>
        /// Identification field
        /// </summary>
        int Id { get; set; }

        /// <summary>
        /// Site group id
        /// </summary>
        int? SiteGroupId { get; set;}

        /// <summary>
        /// Site id
        /// </summary>
        int? SiteId { get; set; }

        /// <summary>
        /// 
        /// </summary>
        SiteAwareCategory SiteCategory { get; }
    }

    public static class SiteAwareEntityObjectExt
    {
        public static SiteAwareCategory GetCategory(this ISiteAwareEntityObject obj)
        {
            Guard.ArgumentNotNull(obj, "obj");

            SiteAwareCategory result = SiteAwareCategory.NotDefined;

            if (obj.SiteId.HasValue)
            {
                result = SiteAwareCategory.Site;
            }
            else if (obj.SiteGroupId.HasValue)
            {
                result = SiteAwareCategory.SiteGroup;
            }
            else
            {
                result = SiteAwareCategory.AllSiteGroups;
            }

            return result;
        }
    }
}
